'use strict';
angular
    .module('myApp.vmoiveDetail', [
        'ngRoute',
        'moviecat.services.http',
    ])
    .config(['$routeProvider', function($routeProvider) {
        $routeProvider.when('/detail/:id', {
            templateUrl: 'view/moiveDetail/view.html',
            controller: 'moiveDetailCtrl'
        });
    }])
    .controller('moiveDetailCtrl', ['$scope',
        '$interval',
        'HttpService',
        '$route',
        '$routeParams',
        'moiveConfig',
        function($scope, $interval, HttpService, $route, $routeParams, moiveConfig) {
            $scope.title = 'Loading...';
            $scope.complete = true;
            $scope.progress = 0;
            // 进度条
            $interval(() => {
                $scope.progress += Math.round(20 + Math.random() * 10);
            }, 500);
            // 分页
            $scope.moiveDetailData = {};
            HttpService.jsonp(`${moiveConfig.detailUlr}${$routeParams.id}`, {},
                function(res) {
                    $scope.title = res.title;
                    $scope.complete = false;
                    $scope.moiveDetailData = res;
                    $scope.progress = 100;
                    $scope.$apply();
                });
        }
    ]);